/**
 * @file Rs485_bsp.h
 * @author Chen Jiale (530673764@qq.com)
 * @brief RS485硬件初始化头文件
 * @version V1.0.0
 * @date 2023-12-09
 * 
 * @copyright Moorgen Intelligent Technologies Copyright (c) 2023
 * 
 */
#ifndef		 __RS485_BSP_H__
#define 	 __RS485_BSP_H__
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include "gd32e10x.h"

//常用波特率
typedef enum _BAUD_TYPE
{
	BAUD_1200=1200,
	BAUD_2400=2400,
	BAUD_4800=4800,
	BAUD_9600=9600,
	BAUD_19200=19200,
	BAUD_38400=38400,
	BAUD_43000=43000,
	BAUD_56000=56000,
	BAUD_57600=57600,
	BAUD_115200=115200,
} enumBaudType;

#define	 USART_BAUDRATE		BAUD_19200	//Mobus波特率

//串口
#define RS485_USART				USART0
#define RS485_USART_IRQn		USART0_IRQn
#define RS485_USART_RCC		RCC_APB2Periph_USART1
//发送使能脚
#define RS485_DE_GPIO_RCC	RCC_APB2Periph_GPIOA
#define RS485_DE_PORT			GPIOA
#define RS485_DE_PIN				GPIO_PIN_8
//外部中断脚
#define RS485_INT_GPIO_RCC	RCC_APB2Periph_GPIOA
#define RS485_INT_PORT			GPIOA
#define RS485_INT_PIN				GPIO_PIN_11
#define RS485_EXTI_LINE			EXTI_Line11
#define RS485_PORT_SOURCES	GPIO_PortSourceGPIOA
#define RS485_PIN_SOURCES		GPIO_PinSource11
//Rs485发送接收脚
#define RS485_Tx_GPIO_RCC	RCC_APB2Periph_GPIOA
#define RS485_Tx_PORT				GPIOA
#define RS485_Tx_PIN					GPIO_PIN_9
#define RS485_Rx_GPIO_RCC	RCC_APB2Periph_GPIOA
#define RS485_Rx_PORT			GPIOA
#define RS485_Rx_PIN				GPIO_PIN_10

//总线忙检测(外部中断调用)
void Rs485_ExtiIsr(void);
/**
 * @brief 串口中断处理(串口中断调用)
 * 
 * @author Chen Jiale (530673764@qq.com)
 * @date 2023-12-09
 */
void Rs485_Recv_Isr(void);
//串口发送
void Rs485_Send(unsigned char *pbuf,unsigned char length);
/**
 * @brief Rs485初始化
 * 
 * @author Chen Jiale (530673764@qq.com)
 * @date 2023-12-09
 */
void Rs485_Init(void);
#endif






